1567B - MEXor Mixup - CodeForces Solution


bitmasks greedy *1000

Please click on ads to support us..

Python Code:

T = int(input())
for _ in range(T):
    a,b = map(int,input().split())
    j = [0,a-1,1,a]
    X = j[a % 4]
    if b == X:
        print(a)
    elif X ^ a == b:
        print(a+2)
    else:
        print(a+1)

C++ Code:

// 1677670931266
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int unsigned long long int
#define mod 1000000007
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define trace(x) cerr << #x << " : " << x << endl;
// #define first cout << "first" << endl;
// #define second cout << "second" << endl;
#define pb push_back
const int e = 1e6;
int fast_pow(int a, int p)
{
  int ret = 1.;
  for (; p; p /= 2, a = ((a % e) * (a % e)) % e)
    if (p & 1)
      ret = (ret % e * a % e) % e;
  return ret % e;
}
int arr[e];
void solve2()
{
  int xr = 0;
  for (int i = 0; i < e; i++)
  {
    xr ^= i;
    arr[i] = xr;
  }
}

void solve()
{
  int n, m;
  cin >> n >> m;
  if (n == 0)
  {
    cout << 2 << endl;
  }
  else
  {

    int ans = arr[n - 1];
    int ans2 = ans ^ m;

    if (ans == m)
    {
      cout << n << endl;
    }
    else if (ans2 == n)
    {
      cout << n + 2 << endl;
    }
    else
    {
      cout << n + 1 << endl;
    }
  }
}

int32_t main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;

  solve2();
  while (t--)
  {
    solve();
  }

  return 0;
}


Comments

Submit
0 Comments
More Questions

13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division